#!/usr/bin/env python3

from euler import *

primes = sorted(list(getprimes(17)))
def testpan(pan):
    test = True
    for x in range(1,8):
        if int(str(pan)[x:x+3]) % primes[x-1] != 0:
            test = False
            break
    return test

pans = getpan(0,9)
total = 0
for pan in pans:
    if(testpan(pan)):
        print(pan)
        total += pan
print("SUM: "+str(total))